package com.example.singleton;

/**
 * @version 1.0.0
 * @className: Singleton
 * @description: 单例模式
 * 一个应用程序中，此类的对象只有一个，getInstance的返回值是一个对象的引用，并不是一个新的实例，
 * @author: rosszhang
 * @date: 2022/5/13 8:30
 */
public class Singleton2 {
    private volatile static Singleton2 singleton;

    private String name;

    private Singleton2() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static Singleton2 getInstance() {
        if (singleton == null) {
            synchronized (Singleton2.class) {
                if (singleton == null) {
                    singleton = new Singleton2();
                }
            }
        }
        return singleton;
    }
}
